package com.xrit.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xrit.sunnyday.dao.MemberDao;
import com.xrit.sunnyday.dao.OrderDao;
import com.xrit.sunnyday.service.MemberService;
import com.xrit.sunnyday.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * 类名称: MemberServiceImpl
 * 类描述:TODO
 * 创建人: czb
 * 创建时间:2022/7/8 上午 11:25
 * Version 1.0.0
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public List<Integer> getMemberReport(List<String> months) {
        List<Integer> memberCount = new ArrayList<>();
        for (String month : months) {
            Integer count = memberDao.findMemberCountBeforeDate(month);
            memberCount.add(count);
        }
        return memberCount;
    }

    @Override
    public HashMap<String, Object> finByDate() {
        HashMap<String, Object> map = new HashMap<>();
        //今天日期 ,周一 ,本月一号 ,本月最后一天,本周最后一天
        String Date = null;
        String week =null;
        String month =null;
        String lastMonth =null;
        String lastWeek =null;
        try {
            Date = DateUtils.parseDate2String(DateUtils.getToday(), "yyyy-MM-dd");
           week= DateUtils.parseDate2String(DateUtils.getThisWeekMonday(), "yyyy-MM-dd");
          month = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth(), "yyyy-MM-dd");
          lastMonth = DateUtils.parseDate2String(DateUtils.getLastDayOfThisMonth(), "yyyy-MM-dd");
          lastWeek = DateUtils.parseDate2String(DateUtils.getLastDayOfWeek(new Date()), "yyyy-MM-dd");
        } catch (Exception e) {
            e.printStackTrace();
        }
        map.put("reportDate", Date);
// ============获取会员数============
        //今日新增的会员数
        Integer todayNewMember = memberDao.findByDate(Date);
        map.put("todayNewMember",todayNewMember);
        //总会员数
       Integer totalMember =  memberDao.findCountAll();
       map.put("totalMember",totalMember);
       //本周新增会员和本月新增会员
       Integer thisWeekNewMember= memberDao.findByWeekAdd(Date,week);
       Integer  thisMonthNewMember = memberDao.findByMonthAdd(Date,month);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);

// ============获取预约人数============
        //今日预约数
       Integer todayOrderNumber= orderDao.getTodayOrderNumber(Date);
        //今日到诊数
        Integer todayVisitsNumber = orderDao.getTodayVisitsNumber(Date);
        //本周预约数
       Integer thisWeekOrderNumber = orderDao.getThisWeekOrderNumber(lastWeek,week);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderDao.getThisWeekVisitsNumber(Date,week);
        //本月预约数
        Integer thisMonthOrderNumber = orderDao.getThisMonthOrderNumber(lastMonth,month);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderDao.getThisMonthVisitsNumber(Date,month);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

//        ==============热门套餐=============
        List<Map<String,Object>> hotSetMeal = orderDao.findByHotSetMeal();
        map.put("hotSetMeal",hotSetMeal);
        return map;
    }
}
